package com.cash.loan.modular.cash.controller;

import com.cash.loan.common.result.PageResult;
import com.cash.loan.common.result.ServerResponse;
import com.cash.loan.modular.cash.service.CateService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * @author Administrator
 * @description
 * @date 2018年10月03 9:36
 */
@RestController
@RequestMapping(value = "/cate")
@Api(description = "产品类别")
public class CateController {

    private static final Logger log = LoggerFactory.getLogger(CateController.class);

    @Autowired
    private CateService cateService;

    @GetMapping(value = "/productList")
    @ApiOperation("类别下面的产品列表")
    public ServerResponse getProductListByCateId(@RequestParam(value = "cateId") Integer cateId,
                                                 @RequestParam(value = "currentPage",required = false,defaultValue = "1") Integer currentPage,
                                                 @RequestParam(value = "pageSize",required = false,defaultValue = "10") Integer pageSize,
                                                 @RequestHeader(value = "uitype",required = false,defaultValue = "0") Integer uiType) {
        PageResult result = cateService.getProductListByCateId(cateId,currentPage,pageSize,uiType);
        return ServerResponse.getSuccess("success",result);
    }

    @GetMapping(value = "/list")
    @ApiOperation("得到所有的产品类别")
    public ServerResponse<List<Map<String,Object>>> getCateList() {
        List<Map<String,Object>> cateList = cateService.getCateList();
        return ServerResponse.getSuccess("success",cateList);
    }
}
